package logic

import (
	"context"
	"fmt"
	"strings"
	"zhaowei/models/mysql"

	"zhaowei/baidurpc/baidurpc"
	"zhaowei/baidurpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentAddLogic {
	return &CommentAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CommentAddLogic) CommentAdd(in *baidurpc.CommentAddRequest) (*baidurpc.CommentAddResponse, error) {
	// todo: add your logic here and delete this line
	var com mysql.Comment
	if strings.Contains(in.Pl, "草") || strings.Contains(in.Pl, "妈") {
		return nil, fmt.Errorf("有敏感词")
	}
	com.UserId = int(in.UserId)
	com.PostId = int(in.PostId)
	com.Pl = in.Pl
	mysql.DB.Debug().Create(&com)
	return &baidurpc.CommentAddResponse{
		Id: int64(com.ID),
	}, nil
}
